from collections import OrderedDict
import datetime
import output
import main

#### Reading samples of running / cycling etc and plotting them
DATA_FOLDER = "Data"
CLASS_DATA_FILENAME = "TransportDataDetail.txt"
WIFI_DATA_FILENAME = "1b768f942564005168dda562defa5b_1415645712_wifi.bigdata"

start_date = datetime.datetime(2014, 9, 10, 0, 0)
end_date = datetime.datetime(2014, 9, 11, 0, 0)

def take_part_of_data(data, start_date, end_date):
    res = OrderedDict()
    for router in data.keys():
        date_list = []
        for s_date in data[router]:
            if s_date[0] < end_date and s_date[0] >= start_date:
                date_list.append(s_date)
        if len(date_list) > 0:
            res[router] = date_list
    return res
    
class_data = main.loadTransportData(DATA_FOLDER + "//" + CLASS_DATA_FILENAME)
    
modes = ['walk', 'bike', 'train', 'bus', 'run']   
#for mode in modes:     
for idx in xrange(0, len(class_data.items()) - 1):
    item = class_data.items()[idx]
    next_item = class_data.items()[idx + 1]
#        if item[1] == mode:
    start_date = item[0]
    end_date = next_item[0]
    scan_data_binned = main.loadScanDataBinned(DATA_FOLDER + "//" + WIFI_DATA_FILENAME, start_date, end_date)
    if len(scan_data_binned.items()) > 0 and start_date > datetime.datetime(2014, 9, 16, 8, 7):
        output.plot_figure_scatter(scan_data_binned, class_data, start_date, end_date, item[1] + datetime.datetime.strftime(start_date, "%Y-%m-%d-%H-%M") + datetime.datetime.strftime(end_date, "%Y-%m-%d-%H-%M") + ".pdf", (8,6), False, {}, {})
#                output.plot_figure_1(scan_data_part, start_date - datetime.timedelta(minutes = 1), end_date + datetime.timedelta(minutes = 1), mode + datetime.datetime.strftime(start_date, "%Y-%m-%d-%H-%M") + ".pdf", (8,6))t_figure_1(scan_data_binned_frequent, min(dates), max(dates), "data_bin_" + str(delta) + "min_least_frequent" + datetime.datetime.strftime(start_date, "%Y-%m-%d") + ".pdf", (8,6), True)